<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>Document</title>
  </head>
  <body>
    <script>
      var ShiftCorrectMethod = 0;
      //修正获取浏览器可视区域左上角坐标位置的方法类型，
      // 模式0是采用window.outerWidth - window.innerWidth方法修正
      // 模式1是采用鼠标活动事件关联方法

      /**
       * 获得可视区域左上角的X屏幕坐标
       * @returns {*}
       */
      function getViewAreaLeft() {
        if (ShiftCorrectMethod == 0) {
          return window.screenLeft + (window.outerWidth - window.innerWidth);
        } else {
          if (window.bodyOffset)
            return window.screenLeft + window.bodyOffset[0];
          else return window.screenLeft;
        }
      }

      /**
       * 获得可视区域左上角的Y屏幕坐标
       * @returns {*}
       */
      function getViewAreaTop() {
        if (ShiftCorrectMethod == 0) {
          return window.screenTop + (window.outerHeight - window.innerHeight);
        } else {
          if (window.bodyOffset) return window.screenTop + window.bodyOffset[1];
          else return window.screenTop;
        }
      }

      console.log(getViewAreaTop());
      console.log(getViewAreaLeft());
    </script>
  </body>
</html>
